// 集成测试 入参放在文件夹中进行测试

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
public class InfConnectControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void testCreateSheet() throws Exception {
        // 将文件放在resource 文件夹下的unit文件夹中，读取转换为string请求http
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource("unit/creat.json").getFile());
        StringBuilder contentBuilder = new StringBuilder();
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            String currentLine;
            while ((currentLine = br.readLine()) != null) {
                contentBuilder.append(currentLine).append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        String instr = contentBuilder.toString();

        // Create the expected output VO
        ComplaintOutVO expectedComplaintOutVO = new ComplaintOutVO();

        ResultActions resultActions = mockMvc.perform(post("/api/v2/complaint/createSheet")
                .content(instr)  // 发送的数据
                .contentType("application/json;charset=UTF-8"));
        // 响应数据设置编码
        resultActions.andReturn().getResponse().setCharacterEncoding("UTF-8");
        resultActions.andDo(print())
                .andExpect(status().isOk());
    }
}
